package com.corpcredit.webapp.action;

import java.io.Serializable;

import com.corpcredit.model.Jrjgsxdj;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class JrjgsxdjForm extends BasePage implements Serializable {
    private GenericManager<Jrjgsxdj, Long> jrjgsxdjManager;
    private Jrjgsxdj jrjgsxdj = new Jrjgsxdj();
    private Long id;

    public void setJrjgsxdjManager(GenericManager<Jrjgsxdj, Long> jrjgsxdjManager) {
        this.jrjgsxdjManager = jrjgsxdjManager;
    }

    public Jrjgsxdj getJrjgsxdj() {
        return jrjgsxdj;
    }

    public void setJrjgsxdj(Jrjgsxdj jrjgsxdj) {
        this.jrjgsxdj = jrjgsxdj;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        jrjgsxdjManager.remove(jrjgsxdj.getId());
        addMessage("jrjgsxdj.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            jrjgsxdj = jrjgsxdjManager.get(id);
        } else {
            jrjgsxdj = new Jrjgsxdj();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (jrjgsxdj.getId() == null || jrjgsxdj.getId() == 0);
        jrjgsxdjManager.save(jrjgsxdj);

        String key = (isNew) ? "jrjgsxdj.added" : "jrjgsxdj.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
} 